﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Documents;
using Ivony.Data;
using XCommunity.Data;
using XCommunity.Caching;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace XCommunity.Frames
{
  /// <summary>
  /// 代表一个话题框架对象
  /// </summary>
  public abstract class TopicFrame : ITopicFrame
  {

    /// <summary>
    /// 创建话题框架
    /// </summary>
    /// <param name="service">管理话题的框架服务</param>
    /// <param name="topicId">话题编号</param>
    /// <param name="communitySystem">管辖话题的社区系统</param>
    public TopicFrame( FrameService service, int topicId, ICommunitySystem communitySystem )
    {
      _service = service;
      TopicId = topicId;
      CommunitySystem = communitySystem;
    }




    /// <summary>
    /// 指示话题框架数据是否已经保存
    /// </summary>
    public bool Saved
    {
      get;
      internal set;
    }



    /// <summary>
    /// 获取话题的主题
    /// </summary>
    public IPostFrame GetTheme()
    {
      return GetThemeProtected();
    }

    protected abstract IPostFrame GetThemeProtected();


    /// <summary>
    /// 获取所有回应。
    /// </summary>
    public IEnumerable<IPostFrame> GetResponses()
    {
      return GetResponsesProtected();
    }

    protected abstract IEnumerable<IPostFrame> GetResponsesProtected();


    /// <summary>
    /// 从一个流中加载框架数据
    /// </summary>
    /// <param name="stream">用于加载框架数据的流</param>
    public abstract void Load( Stream stream );

    /// <summary>
    /// 保存框架数据到一个流
    /// </summary>
    /// <param name="stream">用于保存框架数据的流</param>
    public abstract void Save( Stream stream );


    /// <summary>
    /// 加入这个个话题的讨论
    /// </summary>
    /// <param name="document"></param>
    /// <returns></returns>
    public abstract GeneralPostFrame AttachTopic( Document document );





  }
}
